var username=localStorage.getItem("username");
var token=localStorage.getItem("token");
var userid=localStorage.getItem("userid");
$(function(){
	var paramMap = params();
	var id = paramMap['id'];
	$.ajax({
		url:server_url + "/rest/supplyCommission/getCommission.do",
		data:{supplyID:id},
		success:function(data){
			console.log(data);
			if (data.retCode == "0000") {
				pasteData(data.data);
			} else{
				easyDialog.open({
					container:{
						header:'温馨提示',
						content:data.retMsg
					},
					autoClose : 2000
				});
			}
		}
	});
	
	//表单验证
	var validate = $("form").validate({		   
			rules:{					
				productDisprice:{
					  required:true,
					  stringMaxLength:30
				},
				perMillage:{
					   required:true,
					   stringMaxLength:30
				 },
				 orderPercentage:{
					   required:true,
					   stringMaxLength:30
				},
				overNumber:{
					   required:true,
					   stringMaxLength:30
				},
				limitNumber:{
					   required:true,
					   stringMaxLength:30
				}
			},
			messages:{		
				productDisprice:{
					required:"该值不能为空！",
					stringMaxLength:"最多能输入30个字符！"
				},
				perMillage:{
					required:"该值不能为空！",
	                stringMaxLength:"最多能输入30个字符！"
				 },
				 orderPercentage:{
					required:"该值不能为空！",
	                stringMaxLength:"最多能输入30个字符！"
				},
				overNumber:{
					required:"该值不能为空！",
	                stringMaxLength:"最多能输入30个字符！"
				},
				limitNumber:{
					required:"该值不能为空！",
	                stringMaxLength:"最多能输入30个字符！"
				}
				
			},
			errorPlacement: function(error, element) {
				if ( element.is(":radio") )
					error.appendTo ( element.parent() );
				else if ( element.is(":checkbox") )
					error.appendTo ( element.parent() );
				else if ( element.is("input[name=captcha]") )
					error.appendTo ( element.parent() );
				else
					error.insertAfter(element);
			},
			validClass : 'rightValidate',
		    success: function(label) {
			   label.html("&nbsp;").text(" ") ;
		    }
	 });
});
function pasteData(data){
	console.log(data);
	if(!exist(data)){
		return;
	}
	$("#supplyID").text(data.supplyID);
	$("input[name=supplyID]").val(data.supplyID);
	$("#supplyName").text(data.supplyName);
	$("input[name=supplyName]").val(data.supplyName);
	
	$("#productDisprice").val(data.productDisprice);
	$("#perMillage").val(data.perMillage);
	$("#orderPercentage").val(data.orderPercentage);
	$("#overNumber").val(data.overNumber);
	$("#limitNumber").val(data.limitNumber);
}
function submitCommit(){
	if(!$("form").valid()){
		return;
	}
	$.ajax({
		data:$("form").serialize(),
		url:server_url+'/rest/supplyCommission/editCommission.do?token='+token+'&ran='+Math.random(),
		success:function(){
			easyDialog.open({
				container:{
					header:'温馨提示',
					content:"提交成功",
					yesFn:function(){
						var url=server_url+'/supplyCommission/commissionList.do';
						tl_config.last_url=url;
						tl_config.loadToWorkArea(url);
					}
				}
			});
		},
		error:function(data){
			easyDialog.open({
				container:{
					header:'温馨提示',
					content:data.msg
				},
				autoClose : 2000
			});
		}
	});
}
function back(){
	var url=server_url+'/supplyCommission/commissionList.do';
	tl_config.last_url=url;
	tl_config.loadToWorkArea(url);
}